package com.hjm.system.controller.exam;

import com.hjm.common.core.domain.Result;
import com.hjm.common.core.domain.page.TableDataInfo;
import com.hjm.common.core.controller.BaseController;
import com.hjm.system.domain.exam.dto.ExamSaveDTO;
import com.hjm.system.domain.exam.dto.ExamQueryDTO;
import com.hjm.system.domain.exam.dto.ExamQuestionAddDTO;
import com.hjm.system.domain.exam.vo.ExamDetailVO;
import com.hjm.system.service.exam.impl.ExamServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Autowired
    ExamServiceImpl examService;

    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO){
        return getTableData(examService.list(examQueryDTO));
    }


    @PostMapping("/add")
    public Result<String> add(@RequestBody ExamSaveDTO examAddDTO){
        return Result.ok(examService.add(examAddDTO));
    }

    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody ExamSaveDTO examAddDTO){
        return toResult(examService.edit(examAddDTO));
    }

    @PostMapping("/question/add")
    public Result<Void> addQuestion(@RequestBody ExamQuestionAddDTO queryDTO){
        return toResult(examService.addQuestion(queryDTO));
    }


    @GetMapping("/detail")
    public Result<ExamDetailVO> detail(Long examId){
        return Result.ok(examService.detail(examId));
    }


    @DeleteMapping("/question/delete")
    public Result<Void> deleteQuestion(Long examId, Long questionId){
        return toResult(examService.deleteQuestion(examId,questionId));
    }


    @DeleteMapping("/delete")
    public Result<Void> delete(Long examId){
        return toResult(examService.delete(examId));
    }


    @PutMapping("/publish")
    public Result<Void> publish(Long examId){
        return toResult(examService.publish(examId));
    }


    @PutMapping("/cancelPublish")
    public Result<Void> cancelPublish(Long examId){
        return toResult(examService.cancelPublish(examId));
    }


    @PutMapping("/check")
    public Result<Integer> check(Long examId){
        return Result.ok(examService.check(examId));
    }

}
